package com.ity.teamanagement;

import com.ity.teamanagement.utils.UUIDUtils;
import io.swagger.annotations.ApiModel;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author coderFu
 * @create 2021/6/4
 */
@ApiModel("测试类")
public class Test {
    static  String baseName = "tea_images";
    static String imgPath = System.getProperty("user.dir")+"/../"+baseName+"";

    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSS");
        String res = sdf.format(new Date());
        System.out.println(res);
        //获得项目的存储文件夹
        String property = System.getProperty("user.dir")+"/../";
        String newFile = res+ UUIDUtils.getUUID().toString()+".jpg";
        System.out.println(property);
        System.out.println(newFile);
        Calendar date = Calendar.getInstance();
        File dateDirs = new File(date.get(Calendar.YEAR)
                + File.separator + (date.get(Calendar.MONTH) + 1)
                + File.separator + (date.get(Calendar.DATE)));
        System.out.println(dateDirs);
        String originalFilename =  "C:\\Users\\Administrator\\Desktop\\IMG_2279.JPG";
        String newFileName = res+UUIDUtils.getUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));
        File dateDirsA = new File(date.get(Calendar.YEAR)
                + File.separator + (date.get(Calendar.MONTH) + 1)
                + File.separator + (date.get(Calendar.DATE)));
        File newFileA = new File(imgPath + File.separator + dateDirsA+File.separator + newFileName);
        if (!newFileA.getParentFile().exists()) {
            //如果目标文件所在的目录不存在，则创建父目录
            newFileA.getParentFile().mkdirs();
        }
       // newFileA.mkdirs();
        String desFilePath = baseName + File.separator + dateDirs + File.separator + newFileName;
        System.out.println(desFilePath);
        System.out.println(newFileName);
    }


}
